package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 查询当前登录用户的所有地址信息
     * @return
     */
    @Select("select * from address_book ")
    List<AddressBook> queryAllAddressBook();

    /**
     * 新增地址
     * @param addressBook
     * @return
     */
    void addAddressBook(AddressBook addressBook);


    void update(AddressBook addressBook);

    @Select("select * from address_book where id=#{id}")
    AddressBook queryAddressBookById(Long id);

    @Delete("delete from address_book where id =#{id}")
    void deleteAddressBookById(Long id);

    /**
     * 将当前所有地址改为非默认地址
     * @param addressBook
     */
    /**
     * 根据 用户id修改 是否默认地址
     * @param addressBook
     */
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);
}
